package datasv.collegeQuery_datasv;

import java.util.ArrayList;
import java.util.List;
import data.datafactory.DatabaseOperator;

public class GetCollegeMemberList {
	public static void main(String[] args) {
		System.out.println(new GetCollegeMemberList().getCollegeMemberList("003", MemberType.STUDENT));
		System.out.println(new GetCollegeMemberList().getCollegeMemberList("003", MemberType.TEACHER).get(0));
		System.out.println("getCollege Successful");
	}
	public ArrayList<String> getCollegeMemberList(String collegeID,MemberType type){
		return getCollegeMemList(collegeID,type);
	}
	private ArrayList<String> getCollegeMemList(String id,MemberType type){
		DatabaseOperator dataop=new DatabaseOperator("college"+id);
		ArrayList<String> listID=null;
		ArrayList<String> listName=null;
		ArrayList<String> list=new ArrayList<String>();
		if(!dataop.ifDatabaseExist()){
			return list;
		}
		if(type.equals(MemberType.STUDENT)){
			listID=dataop.getColumn("student_list", "id");
			listName=dataop.getColumn("student_list", "name");
		}else if(type.equals(MemberType.TEACHER)){
			listID=dataop.getColumn("teacher_list", "id");
			listName=dataop.getColumn("teacher_list", "name");
		}else{
			System.out.println("MemberType Wrong");
			return list;
		}
		
		for (int i = 0; i < listID.size(); i++) {
			if(listID.get(i).substring(0,3).equals(id)){
				list.add(listID.get(i));
			}
		}
		return list;
	}
}
